package com.snoopy.gas1.mapper;

import com.snoopy.gas1.entity.Station_info;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface Station_infoMapper {
    // 查询所有加油站
    List<Station_info> lists();

    // 新增加油站
    @Insert("INSERT INTO station_info(station_name, address, responsible_person) " +
            "VALUES(#{stationName}, #{address}, #{responsiblePerson})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insert(Station_info station);

    // 根据ID查询加油站
    @Select("SELECT * FROM station_info WHERE id = #{id}")
    Station_info getById(Integer id);

    // 更新加油站信息
    @Update("UPDATE station_info SET station_name=#{stationName}, address=#{address}, " +
            "responsible_person=#{responsiblePerson} WHERE id=#{id}")
    int update(Station_info station);

    // 根据ID删除加油站
    @Delete("DELETE FROM station_info WHERE id = #{id}")
    int delete(Integer id);

    // 根据名称搜索加油站
    @Select("SELECT * FROM station_info WHERE station_name LIKE CONCAT('%', #{name}, '%')")
    List<Station_info> searchByName(String name);
}